<template>
    <div>
        <h2>科室信息显示</h2>
        <input type="button" value="退出登录" @click="tui">
        <input type="button" value="科室添加" @click="addks">
        <input type="button" value="医生添加" @click="addys">
        <br>
        名称<input v-model="obj.name" type="text">
        介绍<input v-model="obj.jieshao" type="text">
        时间<input type="date" v-model="obj.date1" name="" id="">--
        <input type="date" v-model="obj.date2" name="" id="">
        <input type="button" value="查询" @click="cha">
        <input type="button" value="重置" @click="chong">
        <table class="table">
            <thead>
                <tr>
                    <td>名称</td>
                    <td>科室人数</td>
                    <td>科室介绍</td>
                    <td>创建时间</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="i in data">
                    <td>{{i.name}}</td>
                    <td>{{i.pnum}}</td>
                    <td>{{i.jieshao}}</td>
                    <td>{{i.createdate.substring(0,10)}}</td>
                    <td>
                        <input type="button" value="删除" @click="del(i.id)">
                        <input type="button" value="修改" @click="update(i.id)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { useCounterStore } from '@/stores/counter';
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
const use=useCounterStore();
const route= useRoute();
const router=useRouter();

onMounted(()=>{
    show();
})
const data=ref([ {
    "id": 2,
    "name": "",
    "pnum": 0,
    "jieshao": "",
    "createdate": "",
    "del": false,
    "people": "admin",
    "adddate": "2025-02-18T15:46:54.5152157"
  }])
const obj=ref({
    name:'',
    jieshao:'',
    date1:'',
    date2:''
})
const show=()=>{
    axios.get('https://localhost:7260/api/KeShi/GetKeshis',{params:obj.value}).then(res=>{
        data.value=res.data
    })
}
const cha=()=>{
    show();
}
const chong=()=>{
    obj.value.name='';
    obj.value.jieshao='';
    obj.value.date1='';
    obj.value.date2='';
    show();
}
const del=(id:any)=>{
    if(confirm('确认删除吗？'))
    axios.delete('https://localhost:7260/api/KeShi/DeleteKeshi',{params:{id:id}}).then(res=>{
        if(res.data>0){
            alert('删除成功');
            show();
        }
        else{
            alert('失败');
        }
    })
}
const update=(id:any)=>{
    router.push({
        path:'/updateks',
        query:{id:id}
    })
}
const addks=()=>{
    router.push('/addks');
}
const addys=()=>{
    router.push('/addys');
}
const tui=()=>{
    use.userlogin.islogin=false;
    router.push('/');
}
</script>

<style scoped>

</style>